package com.horizon.manage.endpoint.component;

import com.horizon.manage.endpoint.entity.Endpoint;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Component
public class EndpointObjectKeyGenerator implements KeyGenerator {

    private static final String ENDPOINT_CACHE_KEY_FORMAT = "%s-%d";

    @Override
    public Object generate(Object target, Method method, Object... params) {
        Endpoint endpoint = (Endpoint) params[0];
        return String.format(ENDPOINT_CACHE_KEY_FORMAT, endpoint.getTenantId(), endpoint.getId());
    }
}